/*************************************************************************
	> File Name: test11.cc
	> Author: H.M. Lau
	> Mail: hm.lau@outlook.com
	> Created Time: 2023/09/21 13:13
 ************************************************************************/

#include <iostream>
#include <signal.h>

volatile int flag = 0;

void changeFlag(int signum)
{
    (void)signum;
    std::cout << "Change flag:" << flag;
    flag = 1;
    std::cout << "->" << flag << std::endl;
}

int main(int argc, char *argv[])
{
    signal(2, changeFlag);
    while (!flag);
    std::cout << "After the exit of process normally:" << flag << std::endl;
    return 0;
}
